﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.IO;
using System.Xml.Serialization;

namespace SharedUtils
{
    public class PictureEntity : Entity
    {
        // Texture holding entity's picture
        [XmlIgnore]
        public Texture2D picture { get; set; }

        // File location for texture
        public String picturePath { get; set; }

        // Vector2 that scales Texture2D to proper size
        public Vector2 pictureSize { get; set; }

        public float rotation {get; set;}

        public PictureEntity()
            : base()
        {
            picturePath = string.Empty;
            this.pictureSize = Vector2.Zero;
        }

        public PictureEntity(String name, Vector2 position, String path, Vector2 pictureSize)
            : base(name, position)
        {
            picturePath = path;
            this.pictureSize = pictureSize;
        }

        public PictureEntity(PictureEntity toCopy)
            : base(toCopy.name, toCopy.position)
        {
            this.picturePath = toCopy.picturePath;
            this.pictureSize = toCopy.pictureSize;
        }

        public static Texture2D GetTextureFromStream(GraphicsDevice d, string filepath)
        {
            try
            {
                FileStream s = new FileStream(filepath, FileMode.Open);
                return Texture2D.FromStream(d, s);
            }
            catch (System.Exception ex)
            {
                return null;
            }
        }
    }
}
